package com.dsr.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


/**
 * @author dsr
 * @since 2020-09-26
 */
@Aspect
@Component
public class AuthorityAspect {

    //Controller层切点
    @Pointcut("execution (* com.dsr.controller..*.*(..))")
    public void controllerAspect() {

    }

//    /*
//     * 前置通知 用于拦截Controller层记录用户的操作
//     */
//    @Before("controllerAspect()")
//    public void doBefore(JoinPoint joinPoint) {
//        System.out.println("前置通知");
//    }

    @Around("@annotation(authority)")
    public Object around(ProceedingJoinPoint joinPoint, Authority authority) throws Throwable {
        String value = authority.value();
        System.out.println("authentication = " + value);
        System.out.println(value);
        if("".equals(value))
        {
            return null;
        }else {
            return joinPoint.proceed();
        }

    }

}
